<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="click">
      {{ state.message }}
      </button>
  </div>
  <!-- <script src="https://libs.cdnjs.net/vue/3.0.0-rc.5/vue.global.js"></script> -->
  <script src="./vue.global.js"></script>
  <script>
    const {
        createApp,
        reactive, // 创建响应式数据对象
        ref, // 创建一个响应式的数据对象
        toRefs, // 将响应式数据对象转换为单一响应式对象
        isRef, // 判断某值是否是引用类型
        computed, // 创建计算属性
        watch, // 创建watch监听
        // 生命周期钩子
        onMounted,
        onUpdated,
        onUnmounted,
    } = Vue
    function useMouse() {
      const state = reactive({
          x: 0,
          y: 0
      })
      const update = e => {
          state.x = e.pageX
          state.y = e.pageY
      }
      onMounted(() => {
          window.addEventListener('mousemove', update)
      })
      onUnmounted(() => {
          window.removeEventListener('mousemove', update)
      })
      return toRefs(state)
    }

    function useOtherLogic() {
      const state = reactive({
          time: ''
      })
      onMounted(() => {
          setInterval(() => {
              state.time = new Date()
          }, 1000)
      })
      return toRefs(state)
    }
  </script>
  <script>
      const com = {
        template: `<div>x:{{ x }} y:{{ y }} z:{{ time }} </div>`,
        setup() {
          const { x, y } = useMouse()
          // 与其它函数配合使用
          const { time } = useOtherLogic()
          return { x, y, time }
        }
      }
      const vm = Vue.createApp(com).mount('#app')
  </script>
</body>
</html>